﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SimpleFramework
{
#if UNITY_EDITOR
    [System.Serializable]
#endif
    public class Reference
    {
#if UNITY_EDITOR
        [SerializeField]
#endif
        private int m_RefCount = 0;
        private float m_LastTime = 0;

        public int RefCount { get { return m_RefCount; } }
        public float Time { get { return Timer.time - m_LastTime; } }

        public Reference()
        {
            m_LastTime = Timer.time;
        }

        /// <summary>
        /// 增加引用
        /// </summary>
        public void AddRef()
        {
            m_RefCount++;
            m_LastTime = Timer.time;
        }

        /// <summary>
        /// 删除引用
        /// </summary>
        public void RemoveRef()
        {
            m_RefCount--;
            m_LastTime = Timer.time;
        }

        /// <summary>
        /// 清理引用
        /// </summary>
        protected void ClearRef()
        {
            m_RefCount = 0;
            //m_LastTime = UnityEngine.Time.time;
        }
    }

}
